package com.leyou.auth.config;

import com.leyou.common.auth.utils.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PrivateKey;
import java.security.PublicKey;

/**
 * @author 虎哥
 */
@Slf4j
@Data
@ConfigurationProperties("ly.jwt")
public class JwtProperties /*implements InitializingBean */{
    /**
     * 公钥地址
     */
    private String pubKeyPath;
    /**
     * 私钥地址
     */
    private String priKeyPath;

    /**
     * 公钥对象
     */
    private PublicKey publicKey;
    /**
     * 私钥对象
     */
    private PrivateKey privateKey;

    @PostConstruct
    public void init(){
        try {
            // 加载公钥
            publicKey = RsaUtils.getPublicKey(pubKeyPath);
            // 加载私钥
            privateKey = RsaUtils.getPrivateKey(priKeyPath);
        } catch (Exception e) {
            log.error("【ly-auth】加载公钥失败！", e);
            throw new RuntimeException(e);
        }
    }

    /*@Override
    public void afterPropertiesSet() throws Exception {
        try {
            // 加载公钥
            publicKey = RsaUtils.getPublicKey(pubKeyPath);
            // 加载私钥
            privateKey = RsaUtils.getPrivateKey(priKeyPath);
        } catch (Exception e) {
            log.error("【ly-auth】加载公钥失败！", e);
            throw new RuntimeException(e);
        }
    }*/
}
